<?php
	require_once 'exceptions.php';
	class BaseManager {
		protected $conn;
		
		public function __construct ($conn) {
			$this->conn = $conn;
		}
		
		//for select
		protected  function executeQuery ($query) {
			$result = mysql_query($query, $this->conn);
			if (!$result)
				throw new QueryException(mysql_error(), 1);
			$ret = array();
			while ($row = mysql_fetch_assoc($result)) {
				$ret[] = $row;
			}
			return $ret;
		}
		
		//for delete, update and insert
		protected function query ($query, $flag = true) {
			$result = mysql_query($query, $this->conn);
//			if ($flag) {
//				if (!$result || (mysql_affected_rows($this->conn) <= 0))
//					throw new QueryException(mysql_error(), 3);
//			}
		}
		
		protected function getLastInsertedID () {
			return mysql_insert_id($this->conn);
		}
	}
?>